package cn.mesmile.flink.jdkstream;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zb
 * @date 2021/8/18 23:18
 * @Description
 */
public class JdkStreamTest {

    public static void main(String[] args) {

        //总价 35
        List<VideoOrder> videoOrders1 = Arrays.asList(
                new VideoOrder("20190242812", "springboot教程", 3),
                new VideoOrder("20194350812", "微服务SpringCloud", 5),
                new VideoOrder("20190814232", "Redis教程", 9),
                new VideoOrder("20190523812", "⽹⻚开发教程", 9),
                new VideoOrder("201932324", "百万并发实战Netty", 9));
        //总价 54
        List<VideoOrder> videoOrders2 = Arrays.asList(
                new VideoOrder("2019024285312", "springboot教程", 3),
                new VideoOrder("2019081453232", "Redis教程", 9),
                new VideoOrder("20190522338312", "⽹⻚开发教程", 9),
                new VideoOrder("2019435230812", "Jmeter压⼒测试", 5),
                new VideoOrder("2019323542411", "Git+Jenkins持续集成", 7),
                new VideoOrder("2019323542424", "Idea全套教程", 21));

        Double collect = videoOrders1.stream().collect(Collectors.averagingDouble(VideoOrder::getMoney));
        Double collect2 = videoOrders2.stream().collect(Collectors.averagingDouble(VideoOrder::getMoney));
        System.out.println("collect 订单一平均值 = " + collect);
        System.out.println("collect 订单二平均值 = " + collect2);

        Integer collect3 = videoOrders1.stream().mapToInt(VideoOrder::getMoney).sum();
        System.out.println("collect1 = " + collect3);
        Integer collect4 = videoOrders2.stream().mapToInt(VideoOrder::getMoney).sum();
        System.out.println("collect2 = " + collect4);


    }
}
